package com.tingyuge.thinking.spring.dependency.lookup;

import org.springframework.beans.factory.BeanCreationException;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

/**
 * {@link BeanCreationException}
 * @author xiaodao
 * @version 1.0
 * @date 2021/6/27
 */
public class BeanCreationExceptionDemo {
    public static void main(String[] args) {
        AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext();
        //注册 beanDefinition
        BeanDefinitionBuilder beanDefinitionBuilder =BeanDefinitionBuilder.genericBeanDefinition(POJO.class);

        /*在初始化bean的时候,抛出异常*/
        applicationContext.registerBeanDefinition("errorBean",beanDefinitionBuilder.getBeanDefinition());
        //启动应用上下文
        applicationContext.refresh();
    }


    static  class POJO implements InitializingBean{

        @Override
        public void afterPropertiesSet() throws Exception {
            throw new Exception("for purpose....");
        }
    }
}
